void CMainDlg::LoadMyResHtml( UINT nHtmlId )
{
	CResourceMngr obj;
	obj.SetModule( (HMODULE)_Module.m_hInst );

	TCHAR szUrl[MAX_PATH] = {0};
	_sntprintf(szUrl, MAX_PATH, _T("RES://HTML/%d"), nHtmlId );

	DWORD dwSize = 0;
	LPTSTR pRetBuff = (LPTSTR)obj.FindResource( szUrl, dwSize );
	if ( pRetBuff && dwSize != 0 )
	{
		CComPtr<IDispatch> spDispatch = NULL;
		HRESULT hr = m_pWB2->get_Document( &spDispatch );
		
		USES_CONVERSION;
		if ( SUCCEEDED(hr))
		{
			if ( !spDispatch )
			{
				m_pWB2->Navigate( L"about:blank", NULL, NULL, NULL, NULL );
				hr = m_pWB2->get_Document( &spDispatch );
			}
			CComQIPtr<IHTMLDocument2> spDoc(spDispatch);
			if ( spDoc )
			{
				spDoc->close();

				BOOL bModified = FALSE;

				TCHAR* szTxt = NULL;
				if ( nHtmlId == IDR_ERROR )
				{
					LPCTSTR pUrl = A2T((LPSTR)m_sCurrentPageUrl.c_str());
					UINT nUrlLen = _tcslen(pUrl);

					szTxt = new TCHAR[dwSize+nUrlLen+1];
					if ( szTxt )
					{
						ZeroMemory( szTxt, dwSize + nUrlLen + 1 );
						TCHAR* pStart = _tcsstr( pRetBuff, _T("href="));
						if ( NULL != pStart )
						{
							pStart = pStart + _tcslen("href=");
							TCHAR* pEnd = _tcsstr( pStart, _T(">"));
							if (pEnd != NULL )
							{
								_tcsncpy( szTxt, pRetBuff, pStart-pRetBuff );
								_tcscat(szTxt, _T("\""));
								_tcsncpy( szTxt+(pStart-pRetBuff) +1, pUrl,nUrlLen );
								_tcscat(szTxt, _T("\""));
								_tcsncpy( szTxt+ (pStart-pRetBuff)+nUrlLen+2, pEnd, dwSize-(pEnd-pRetBuff));

								bModified = TRUE;
							}
							else
							{
								delete[] szTxt;
								szTxt = NULL;
							}
						}
						else
						{
							delete[] szTxt;
							szTxt = NULL;
						}
					}
				}
				else if (nHtmlId == IDR_HTML_LOAD)
				{
					RECT rcWnd = {0};
					GetWindowRect(&rcWnd);
					int nWidth = rcWnd.right - rcWnd.left;
					int nHeight = rcWnd.bottom - rcWnd.top;
					int nTopPos = (nHeight - 25) / 2 - 25;

					TCHAR szHtmlString[MAX_PATH] = {0};
					_sntprintf_s(szHtmlString, MAX_PATH, _T("width:%dpx; height:%dpx; padding-top:%dpx; text-align:center;"), nWidth, nHeight, nTopPos);
					int nHtmlStringLen = _tcslen(szHtmlString);

					szTxt = new TCHAR[dwSize+nHtmlStringLen+1];
					if ( szTxt )
					{
						ZeroMemory( szTxt, dwSize + nHtmlStringLen + 1 );
						TCHAR* pStart = _tcsstr( pRetBuff, _T("width"));
						if ( NULL != pStart )
						{
							pStart = pStart + _tcslen("width");
							TCHAR* pEnd = _tcsstr( pStart, _T("}"));
							if (pEnd != NULL )
							{
								_tcsncpy(szTxt, pRetBuff, pStart - pRetBuff - _tcslen("width"));
								_tcsncpy(szTxt + (pStart - pRetBuff) - _tcslen("width"), szHtmlString, nHtmlStringLen);
								_tcsncpy(szTxt + (pStart - pRetBuff) - _tcslen("width") + nHtmlStringLen, pEnd, dwSize - (pEnd - pRetBuff));

								bModified = TRUE;
							}
							else
							{
								delete[] szTxt;
								szTxt = NULL;
							}
						}
						else
						{
							delete[] szTxt;
							szTxt = NULL;
						}
					}
				}

				if ( !bModified )
				{
 					szTxt = new TCHAR[dwSize+1];
 					ZeroMemory( szTxt, dwSize+1 );
					memcpy( szTxt, pRetBuff, dwSize );
				}

				VARIANT varName, varFeature, varReplace;
				IDispatch* spWindowResult = NULL;
				
				VariantInit( &varName );
				VariantInit( &varFeature );
				VariantInit( &varReplace );

				varName.vt = VT_BSTR;
				varName.bstrVal = ::SysAllocString(L"_self");

				hr = spDoc->open( ::SysAllocString(L"text/html"), varName, varFeature, varReplace, &spWindowResult );
				if ( SUCCEEDED(hr))
				{
					m_pWB2->Refresh();
				}

				if (spWindowResult != NULL) 
				{
					spWindowResult->Release();
				}
				// construct text to be written to browser as SAFEARRAY
				if (SUCCEEDED(hr))
				{
					SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);

					VARIANT	*variant;
					CComBSTR bstrTxt(szTxt);

					SafeArrayAccessData(safe_array,(LPVOID *)&variant);
					variant->vt      = VT_BSTR;
					//variant->bstrVal = CString(szTxt).AllocSysString();
					variant->bstrVal = bstrTxt.Detach();
					SafeArrayUnaccessData(safe_array);

					// write SAFEARRAY to browser document

					spDoc->write(safe_array);
				}

				if ( NULL != szTxt )
				{
					delete[] szTxt;
					szTxt = NULL;
				}
			}
		}

	}
}
